<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt_br" lang="pt_br">
  <head>
    <?php include_http_metas() ?>
    <?php include_metas() ?>
    <?php include_title() ?>
    <?php include_javascripts() ?> 

    <link rel="shortcut icon" href="http://mail.ctis.com.br/pls/portal/docs/page/intranet/imagens_intranet/link_fav_ctis_intranet.gif" />
  
  </head>
  <body>
    <div id="cabecalho">
      <a href= "<?php echo url_for('camara/principal') ?>">
          <?php echo image_tag('cabecalho.jpg', 'alt=Logo As Camaras do Mapa width=100%') ?>
	  </a>
	  <?php if ($sf_user->hasFlash('notice')): ?>
	    <div class="flash_notice"><?php echo html_entity_decode($sf_user->getFlash('notice')) ?></div>
	  <?php endif; ?>
	 
	  <?php if ($sf_user->hasFlash('error')): ?>
	    <div class="flash_error"><?php echo  html_entity_decode($sf_user->getFlash('error')) ?></div>
	  <?php endif; ?>
    </div>

	<?php if (($sf_user->isAuthenticated()) && (!$sf_user->getAttribute('reset_senha',null,'usr'))) : ?>
        <div id="menu">
        <ul>
          <li id="menu_camara"><a href="<?php echo url_for('camara/principal') ?>" >Câmaras</a></li>
          <li id="menu_calendario"><a href="<?php echo url_for('calendario/index') ?>">Calendário</a></li>
		  <li id="menu_relatorio"><a href="<?php echo url_for('relatorio/index') ?>">Relatório</a></li>
          <li id="menu_pesquisar"><a href="<?php echo url_for('pesquisar/index') ?>">Pesquisar</a></li>
		  <?php if ($sf_user->getAttribute('gerente',null,'usr')) : ?>
            <li id="menu_cadastros"><a href="<?php echo url_for('cadastros/index') ?>">Cadastros</a></li>
		  <?php endif; ?>
          <li id="menu_tema"><a href="<?php echo url_for('tema/index') ?>">Temas</a></li>
          <li><a href="<?php echo url_for('usuario/logout') ?>">Sair</a></li>
      	</ul>

		<script type="text/javascript">
			//ativa menu
			<?php if (@$_SERVER['PATH_INFO']) :
			  //Módulo Camaras
			  $modulo = explode('/', @$_SERVER['PATH_INFO']);
			  $modulo[1] = (     $modulo[1] == '' 
							  || $modulo[1] == 'acao' 
							  || $modulo[1] == 'providencia_acao'
							  || $modulo[1] == 'proposicao'
						   ) ? 'camara' : $modulo[1] ;
			  //Módulo Cadastros
			  $modulo[1] = (  $modulo[1] == 'orgao_externo' 
							  || $modulo[1] == 'usuario'
							  || $modulo[1] == 'cidade'
						   ) ? 'cadastros' : $modulo[1] ;
			else :
			  $modulo[1] = 'camara';
			endif; ?>
			document.getElementById("menu_<?php echo $modulo[1]?>").className="menu_ativo";
		</script>
      </div>
    <?php endif?>        

    <div id="conteudo">
		
        <div id="formulario">
            <?php echo $sf_content ?>
        </div>

	    <?php if (($sf_user->isAuthenticated()) && (!$sf_user->getAttribute('reset_senha',null,'usr'))) : ?>
		  <div id="calendario">

		    <?php
			class Calendario
			{	
			  function cal($mes="",$ano="") {
				$ct = 0;
			  	
				$nomeMes = array(1 => "janeiro", 2 => "fevereiro", 3 => "marco", 4 => "abril", 5 => "maio", 6 => "junho", 7 => "julho", 8 => "agosto", 9 => "setembro", 10 => "outubro", 11 => "novembro", 12 => "dezembro");
				
				(!$mes ? $mes = (int)date("m") : false);
				(!$ano? $ano = (int)date("Y") : false);
				
				$totalDias = date("t", mktime(0,0,0,$mes,1,$ano));

				for($i=1; $i<=$totalDias; $i++)	$dias[] = $i;

				$weekStart = date("w",mktime(0,0,0,$mes,1,$ano));
				@$tmp .= '<table border="0" cellspacing="1" cellpadding="2" width="100%" class="minical">';
				$ano1=date($ano);
				$tmp .= "<tr><th class='thMes' colspan=7>$nomeMes[$mes] $ano1</td>
					     </tr>";
				unset($ano1);
				$tmp .= "<tr><th>dom</th><th>seg</th><th>ter</th><th>qua</th><th>qui</th><th>sex</th><th>sáb</th></tr><tr>";
				for($i=0; $i<$weekStart; $i++){
					$tmp .= "<td>&nbsp;</td>";
					@++$ct;
				}
				foreach($dias as $d){
					$tmp .= "<td id=".sprintf("%02d", $d).sprintf("%02d", $mes).$ano." class=''><a href=".url_for('calendario/index').">$d</a></td>";
					if($ct == "6"){
						$tmp .= "</tr><tr>";
						$ct = -1;
					}
					++$ct;
				}
				if ($ct <> 0) {
				  for($i=$ct-1; $i<6; $i++){ 
					$tmp .= "<td>&nbsp;</td>";
				  }
				}
				$tmp .= "</table> ";
				
				//corrige métodos que abre <tr> mesmo quando não haverá mais dias a imprimir (ex: out 09)
				$tmp = str_replace("<tr></table>","</table>",$tmp, $replace_count);
				
				return $tmp;
			  }
			}
			$c = new Calendario;
			$mes = (int)date("m");
			$ano = (int)date("Y");
			
			$i = 3;
			do {
				echo $c->cal($mes,$ano);
				$mes++;
				if ($mes == 13) {
					$ano++;
					$mes = 1;
				} 
				$i--;
			} while($i>0);
			
	      ?>
		  
          </div>
			<script type="text/javascript">
				<?php if ($sf_user->getAttribute('data',null,'eventos')) : ?>
					<?php $date_list = $sf_user->getAttribute('data',null,'eventos'); ?>
					  
					<?php foreach ($date_list as $date) { ?>
					   document.getElementById("<?php echo date("dmY",strtotime($date))?>").className="negrito";
					<?php } ?>
				<?php endif ?>
			</script>

		<?php endif?>
     </div> 
  </body>
</html>